package co.yeye.test;

import android.content.Intent;
import android.widget.Toast;

import commit.UserDiscovery;
import commit.WriteDiscovery;
import register.Login;

/**
 * Created by yeye on 15/3/1.
 */
public class HandleOptions {

    MainActivity mainActivity;

    public HandleOptions(MainActivity mainActivity){
        this.mainActivity = mainActivity;
    }

    public boolean handlerOption(int id){
        if (id == R.id.action_write) {
            if(!Constance.isUserLogin()){
                turnToLogin();
                return true;
            }
            Intent intent = new Intent(mainActivity, WriteDiscovery.class);
            mainActivity.startActivity(intent);
            //Toast.makeText(getBaseContext(),"发布信息",Toast.LENGTH_SHORT).show();
            return true;
        }
        else if(id == R.id.action_user){
            if(!Constance.isUserLogin()){
                turnToLogin();
                return true;
            }
            Intent intent = new Intent(mainActivity, UserDiscovery.class);
            mainActivity.startActivity(intent);
            return true;
        }
        return false;
    }

    private void turnToLogin(){
        Toast.makeText(mainActivity.getBaseContext(),"请登录",Toast.LENGTH_SHORT).show();
        Intent intent = new Intent(mainActivity, Login.class);
        mainActivity.startActivity(intent);
    }

}
